/**
 * 
 */
package com.dashu.authority.util;

import java.util.Map;

/**
 * @author jiesion
 * update 2016年4月12日 下午2:50:28
 */
/**
 * @author jiesion
 * update 2016年4月12日 下午2:52:09
 */
public class ResultBean {
	
	private Integer status;
	
	private String errorCode;
	
	private String errorMsg;
	
	private String request;
	
	private Object data;
	
	public ResultBean(Integer status, Object data) {
		this.status = status;
		if (data instanceof Map) {
			Map map =(Map) data;
			if (map.get("message")!=null) {
				this.errorMsg = map.get("message").toString();
				map.remove("message");
			} else if (map.get("content")!=null) {
				this.errorMsg = map.get("content").toString();
				map.remove("content");
			}else if (map.get("errorMsg")!=null) {
				this.errorMsg = map.get("errorMsg").toString();
				map.remove("errorMsg");
			}
			if (map.get("code")!=null) {
				this.errorCode =map.get("code").toString();
				map.remove("code");
			}
			map.remove("status");
			map.remove("remark");
			if (map.get("data")!=null) {
				this.data = map.get("data");
			}else{
				this.data=map;
			}
		}else{
			this.data = data;
		}
	}
	
	public ResultBean(Integer status, Object data,String errorMsg) {
		this.status = status;
		this.errorMsg = errorMsg;
		if (data instanceof Map) {
			Map map =(Map) data;
			if (map.get("message")!=null) {
				this.errorMsg = map.get("message").toString();
				map.remove("message");
			} else if (map.get("content")!=null) {
				this.errorMsg = map.get("content").toString();
				map.remove("content");
			}else if (map.get("errorMsg")!=null) {
				this.errorMsg = map.get("errorMsg").toString();
				map.remove("errorMsg");
			}
			if (map.get("code")!=null) {
				this.errorCode =map.get("code").toString();
				map.remove("code");
			}
			map.remove("status");
			map.remove("remark");
			if (map.get("data")!=null) {
				this.data = map.get("data");
			}else{
				this.data=map;
			}
		}else{
			this.data = data;
		}
	}
	
	public ResultBean(Integer status, String errorMsg) {
		this.status = status;
		this.errorMsg = errorMsg;
	}
	
	public ResultBean(Map<String, Object> map) {
		this.status = Integer.valueOf(map.get("status").toString());
		if (map.get("errorMsg")!=null) {
			this.errorMsg = map.get("errorMsg").toString();
			map.remove("errorMsg");
		}else if (map.get("message")!=null) {
			this.errorMsg = map.get("message").toString();
			map.remove("message");
		} else if (map.get("content")!=null) {
			this.errorMsg = map.get("content").toString();
			map.remove("content");
		}
		if (map.get("code")!=null) {
			this.errorCode =map.get("code").toString();
			map.remove("code");
		}
		map.remove("status");
		map.remove("remark");
		if (map.size()>0) {
			if (map.get("data")!=null) {
				this.data = map.get("data");
			}else{
				this.data=map;
			}
		}
	}
	
	public ResultBean(Integer status, String errorCode, String errorMsg,
			String request, Object data) {
		this.status = status;
		this.errorCode = errorCode;
		this.errorMsg = errorMsg;
		this.request = request;
		this.data = data;
	}

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public String getErrorCode() {
		return errorCode;
	}

	public void setErrorCode(String errorCode) {
		this.errorCode = errorCode;
	}

	public String getErrorMsg() {
		return errorMsg;
	}

	public void setErrorMsg(String errorMsg) {
		this.errorMsg = errorMsg;
	}

	public String getRequest() {
		return request;
	}

	public void setRequest(String request) {
		this.request = request;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}

	public Map<Object, Object> getResultMap() {
		return ResultMapUtil.resultMap(this);
	}

}
